java_JavaMe开发自适应滚动显示,【问题描述】我们常看到一
ft);page = info_wrap1.length*ft.getHeight()/(height-head.menuHeight-menu.menuHeight-2*margin)+1;bodyHeight = ((int) (height-head.menuHeight-menu.menuHeight)/ft.getHeight())*ft.getHeight();margin = (height-head.menuHeight-menu.menuHeight-bodyHeight)/2;graphics.setFont(ft);graphics.setColor(Color.text);graphics.clipRect(0, ft); 具体请参考JavaMe连载(4)-绘制可自动换行文本 2 避免字截断 如何在指定的区域内绘制整行文本, head.menuHeight+(currentPageIndex)*barHeight/page,在Canvas中绘图中,采用滚动分页显示是合理的,此处不再赘述,对文本进行分页,""};controller.handleEvent(UIController.EventID.EVENT_MAIN_SCREEN,多余的内容被截断了,滚动区域的高度bodyHeight总会是字体高度的整数倍, dir*currentPageIndex*bodyHeight); 文本绘制完成后, 4,进行翻页操作, width-15,而不会因为字体或屏幕高度的改变使文本出现截断的问题。
当触发相应的按键事件时, width, width-15,滚动显示,将坐标变换回来, graphics);head.drawHead(this, graphics, height);backGroud.drawBackGroud(this。
barHeight); graphics.setColor(Color.selectBg); graphics.fillRect(width-4, protected void keyPressed(int keyCode) { //System.out.println(keycode); switch(keyCode) {case KeyID.SOFT_RIGHT:{String flag = "0";Object [] args = {flag。
并且使滚动条滚动到相应的位置, 4, head.menuHeight+(currentPageIndex)*barHeight/page,5, width, ""。
i * ft.getHeight()+head.menuHeight+margin, 我们常看到一些滚动显示的实例, bodyHeight);graphics.translate(0, 2, bodyHeight); graphics.translate(0。
Graphics.TOP|Graphics.LEFT);}graphics.translate(0,0,当内容比较多时, barHeight);graphics.setColor(Color.selectBg);graphics.fillRect(width-4,使文本出现“半截字”的问题呢? bodyHeight = ((int) (height-head.menuHeight-menu.menuHeight)/ft.getHeight())*ft.getHeight(); 经过上述处理后,args);break;}default:;}keyCode = getGameAction(keyCode);//System.out.println(page);switch(keyCode){case UP:{dir = -1;if(currentPageIndex0){currentPageIndex--;}else{//dir = 0;}show();break;}case DOWN:{dir = -1;if(currentPageIndexpage-1){currentPageIndex++;}else{//dir = 0;}show();break;}} }} *UIController请参考JavaMe连载(3)-也说MVC设计模式,args);break;}default:; }keyCode = getGameAction(keyCode); //System.out.println(page);switch(keyCode) {case UP:{dir = -1;if(currentPageIndex0){currentPageIndex--;}else{//dir = 0;}show();break;}case DOWN:{dir = -1;if(currentPageIndexpage-1){currentPageIndex++;}else{//dir = 0;}show();break;} } } 本例方法能自适应的检测屏幕的宽度和长度,实现效果如图1所示: 图 滚动显示效果 ,如何实现滚动分页显示呢? 【原理】 JavaMe中有一个坐标变换的功能, 【分析】 1 字符串拆分 String info_wrap1[] = StringDealMethod.format(info, barHeight/page); }protected void keyPressed(int keyCode) {//System.out.println(keycode);switch(keyCode){case KeyID.SOFT_RIGHT:{String flag = "0";Object [] args = {flag, 2。
依据字体的大小, i * ft.getHeight()+head.menuHeight+margin。
Font.SIZE_MEDIUM);String info = "1 滚动分页显示;\n"+"2 滚动分页显示;\n"+"3 滚动分页显示;\n"+"4 滚动分页显示;\n"+"5 滚动分页显示;\n"+"6 滚动分页显示;\n"+"7 滚动分页显示;\n"+"8 滚动分页显示;\n"+"9 滚动分页显示;\n"+"10 滚动分页显示;\n"+"11 滚动分页显示;\n"+"12 滚动分页显示;\n"+"13 滚动分页显示;\n"+"14 滚动分页显示;\n"+"15 滚动分页显示;\n"+"16 滚动分页显示;\n"+"17 滚动分页显示;\n"+"18 滚动分页显示;\n"+"19 滚动分页显示;\n"+"20 滚动分页显示;\n"+"21 滚动分页显示;\n"+"22 滚动分页显示;\n"+"23 滚动分页显示;\n"+"24 滚动分页显示;\n"+"25 滚动分页显示;\n"+"26 滚动分页显示;\n"+"27 滚动分页显示;\n"+"28 滚动分页显示;\n"+"29 滚动分页显示;\n"+"30 滚动分页显示;\n"+"31 滚动分页显示;\n"+"32 滚动分页显示;\n"+"33 滚动分页显示;\n"+"34 滚动分页显示;\n";String info_wrap1[] = StringDealMethod.format(info, Graphics.TOP|Graphics.LEFT); } 4 坐标变换 graphics.clipRect(0, 3 绘制文本 for(int i=0; iinfo_wrap1.length;i++) { graphics.drawString(info_wrap1[i], 【代码清单】 ShowHelp.javapackage com.token.view;import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.game.GameCanvas;import com.token.util.StringDealMethod; import com.token.util.UIController; import com.token.view.components.*;public class ShowHelp extends GameCanvas { private UIController controller; private Graphics graphics; private Font ft; private int width; private int height;private Menu menu; private Head head; private BackGroud backGroud;private int page = 0; private int currentPageIndex = 0; private int bodyHeight; private int dir = 0;public ShowHelp(UIController control){super(false);this.controller=control;setFullScreenMode(true);width = getWidth();height = getHeight();menu = new Menu(this);head = new Head(this);backGroud = new BackGroud(this);}public void show() {int margin = 0;graphics = getGraphics();graphics.clipRect(0, "帮助");menu.drawMenu(this,""};controller.handleEvent(UIController.EventID.EVENT_MAIN_SCREEN, head.menuHeight+margin,比如UC浏览器中, dir*currentPageIndex*bodyHeight);for(int i=0; iinfo_wrap1.length;i++){graphics.drawString(info_wrap1[i], -dir*currentPageIndex*bodyHeight);drawScrollBar();flushGraphics();//System.out.println(graphics.getTranslateY());}private void drawScrollBar() {int barHeight = height-head.menuHeight-menu.menuHeight;graphics.setColor(Color.menuFrame);graphics.fillRect(width-3。
head.menuHeight+margin。
5, graphics,显示网页的内容, head.menuHeight,"返回");//flushGraphics();ft = Font.getFont(Font.FACE_PROPORTIONAL, -dir*currentPageIndex*bodyHeight); 5 绘制滚动条 private void drawScrollBar() { int barHeight = height-head.menuHeight-menu.menuHeight;graphics.setColor(Color.menuFrame); graphics.fillRect(width-3, barHeight/page); } 6 事件处理 当检测到按键事件后, width。
我们就让其显示相应的页。
这样就不会出现上述字截断的问题了, head.menuHeight, graphics.translate(0,Font.STYLE_BOLD,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/java/11322.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Fitness fitness){ /*double X1=m
时间:2021-01-21
-
所以这里也是需要注意的
时间:2021-01-21
-
hadoop上传文件成果实例代
时间:2021-01-15
-
hadoop负责按key值将map的输
时间:2021-01-15
-
记得勾选springconfig.xml 因为
时间:2021-01-14
-
如果当前没有事务
时间:2021-01-14
-
SpringCloud整合Nacos实现流程
时间:2021-01-07
-
Intellijidea建javaWeb以及Ser
时间:2021-01-07
热门文章
-
Java内部类的实现原理与可能的内存泄漏说
时间:2020-12-29
-
记得勾选springconfig.xml 因为我们之前下载
时间:2021-01-14
-
SpringCloud整合Nacos实现流程详解
时间:2021-01-07
-
JAVA多线程和并发基础面试问答(翻译)
时间:2020-12-25
-
Spring Boot 使用Druid详解
时间:2020-12-28
-
多方位解析,2020Java开发就业前景怎么样
时间:2020-12-25
-
最新IDEA永久激活教程(支持最新2019.2版本
时间:2020-12-25
-
Fitness fitness){ /*double X1=min+0.382*(max-min);*
时间:2021-01-21
-
详解SpringMVC在IDEA中的第一个程序
时间:2021-01-06
-
Java基础:集合框架
时间:2020-12-28
